/*
 * @Author: yangxiaoqiang 
 * @Date: 2021-06-28 14:54:45 
 * @Last Modified by: yangxiaoqiang
 * @Last Modified time: 2021-07-02 14:05:04
 */

//手动实现bind函数
Function.prototype.myBind = function (context) {
    // 判断调用对象是否为函数
    if (typeof this !== "function") {
        throw new TypeError("Error");
    }

    // 获取参数
    const args = [...arguments].slice(1),
          fn = this;

    return function Fn() {

        // 根据调用方式，传入不同绑定值
        return fn.apply(this instanceof Fn ? new fn(...arguments) : context, args.concat(...arguments)); 
    }
}

//手写实现call apply  bind